<?php

namespace app\product\controller;

use app\common\controller\PCBase;
use app\common\controller\DBase;
use app\common\library\Upload;
use app\product\logic\ProductInventoryLogic;
use app\product\logic\ProductOnwayLogic;
use Throwable;
use  think\App;
class ProductInventory extends PCBase
{

    /**
     * @desc   获取产品库存列表
     * @author luckyXiong
     * @date   2024-07-21
     */
    public function index(){
        $params     = $this->request->post();
        return  (new ProductInventoryLogic())->getList($params);
    }


    /**
     * @desc   获取子集sku数据
     * @author luckyXiong
     * @date   2024-07-26
     */
    public function getSkuList(){
        $params     = $this->request->post();
        return  (new ProductInventoryLogic())->getSkuList($params);
    }


    /**
     * @desc   获取产品导入接口
     * @author luckyXiong
     * @date   2024-07-21
     */
    public function uploadInventory(){
        $file         = $this->request->file('file');
        $tel          = $this->getAdminTel();
        $params       = $this->request->post();
        $type         = $params['type']??'';
        $data['file'] = $file;
        $data['tel']  = $tel;
        if($type =='2'){
            //先更新表中 on_way_quantity,buy_inventory_quantity,arrive_inventory_quantity字段;
            (new ProductOnwayLogic())->change_inventory();
            (new ProductOnwayLogic())->import_inventor_count($data);
        }else{
            (new ProductInventoryLogic())->import_inventor($data);
        }
        return  $this->jsonMessage(200, true, '操作成功,异步上传可能需要5分钟完成!',null);
    }






    /**
     * @desc   获取产品导出接口
     * @author luckyXiong
     * @date   2024-07-22
     */
    public function exportInventory(){
        $params     = $this->request->post();
        return  (new ProductInventoryLogic())->exportInventory($params);
    }

    /**
     * @desc   导出
     */
    public function export(){
        $params     = $this->request->post();
        return  (new ProductInventoryLogic())->export($params);
    }


    /**
     * @desc   获取产品导入消费方法
     * @author luckyXiong
     * @date   2024-07-22
     */
    public function importInventoryConsumer(){
        $params     = $this->request->post();
        $res        = (new ProductInventoryLogic())->importInventoryConsumer($params);
        return  $this->jsonMessage(200, true, '操作成功',$res);
    }


    /**
     * @desc   库存管理编辑
     * @author luckyXiong
     * @date   2024-07-25
     */
    public function edit(){
        $params     = $this->request->post();
        return    (new ProductInventoryLogic())->edit_inventory($params);
    }


    /**
     * @desc   更新spu表字段数据
     * @author luckyXiong
     * @date   2024-08-01
     */
    public function get_purchase_info(){
        $params     = $this->request->post();
        $spu        = $params['spu']??'';
        return    (new ProductInventoryLogic())->get_purchase_info($spu);
    }






    /**
     * @desc   清除数据
     * @author luckyXiong
     * @date   2024-08-02
     */
    public function removeInventory(){
         $params     = $this->request->post();
         $res        = (new ProductInventoryLogic())->removeInventory($params);
         return  $this->jsonMessage(200, true, '操作成功',$res);
    }



    /**
     * @desc   数据排序更新消费方法
     * @author luckyXiong
     * @date   2024-08-01
     */
    public function updateSpuConsumer(){
        $params     = $this->request->post();
        $res        = (new ProductInventoryLogic())->updateSpuConsumer($params);
        return  $this->jsonMessage(200, true, '操作成功','');
    }




    /**
     * @desc   可用库存明细
     * @author zhangheng
     * @date   2025-06-17
     */
    public function StockInfo(){
        $params     = $this->request->post();
        return  (new ProductInventoryLogic())->StockInfo($params);
    }

    /**
     * @desc   可用库存明细导出
     * @author zhangheng
     * @date   2025-06-17
     */
    public function exportStockInfo(){
        $params     = $this->request->post();
        return  (new ProductInventoryLogic())->exportStockInfo($params);
    }

    

    /**
     * @desc   可用库存
     * @author zhangheng
     * @date   2025-06-17
     */
    public function queryStock(){
        $params     = $this->request->post();
        return  (new ProductInventoryLogic())->queryStock($params);
    }


}